package com.example.demo.Controller;

import com.example.demo.Entity.BusinessEntity;
import com.example.demo.Entity.CustomerEntity;
import com.example.demo.Entity.ResultEntity;
import com.example.demo.Service.BusinessService;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/api/business")
@CrossOrigin
public class BusinessController {
    @Resource
    BusinessService businessService;

    @RequestMapping(value = "/getBusinessInfo")
    public ResultEntity GetBusiness() {
        List<BusinessEntity> businessEntities;
        businessEntities = businessService.get();

        ResultEntity res = new ResultEntity();
        res.setCode(20000);
        res.setData(businessEntities);
        return res;
    }

    @RequestMapping(value = "/getBusinessInfoByAccounts")
    public ResultEntity GetBusinessInfoByAccounts(@RequestParam("accounts") String accounts) {
        BusinessEntity businessEntity;
        businessEntity = businessService.getByAccounts(accounts);

        ResultEntity res = new ResultEntity();
        res.setCode(20000);
        res.setData(businessEntity);
        return res;
    }

    @RequestMapping(value = "/updateBusinessInfoByAccounts")
    public ResultEntity UpdateBusinessInfoByAccounts(@RequestBody BusinessEntity data) {
        int businessEntity;
        businessEntity = businessService.updateByAccounts(data.getAccounts(),data.getUsername(),data.getPassword(),data.getAddress(),data.getTelephone(),data.getAvatar(),data.getLicense(),data.getStatus());

        ResultEntity res = new ResultEntity();
        res.setCode(20000);
        res.setData(businessEntity);
        return res;
    }

    @RequestMapping(value = "/addBusiness")
    public ResultEntity AddBusiness(@RequestBody BusinessEntity data) {
        int businessEntity;
        businessEntity = businessService.addBusiness(data.getAccounts(),data.getUsername(),data.getPassword(),data.getAddress(),data.getTelephone(),data.getAvatar(),data.getLicense());

        ResultEntity res = new ResultEntity();
        res.setCode(20000);
        res.setData(businessEntity);
        return res;
    }

    @RequestMapping(value = "/deleteBusiness")
    public ResultEntity DeleteBusiness(@RequestParam("accounts") String accounts) {
        int businessEntity;
        businessEntity = businessService.deleteBusiness(accounts);

        ResultEntity res = new ResultEntity();
        res.setCode(20000);
        res.setData(businessEntity);
        return res;
    }
}
